<template>
  <el-dialog @close="kcfdkqrCancel('kcfdkqrRuleForm')" :close-on-click-modal="false" append-to-body title="勘场费打款确认"
    :visible.sync="kcfdkqrVisible" width="600px">
    <div class="scroll-view">
      <el-descriptions :column="1" border>
        <el-descriptions-item label="收款账户" v-if="fieldShowFunc('kc_receiving_account')">{{ shkxpzData.receiving_account_name }}</el-descriptions-item>
        <el-descriptions-item label="备注描述">{{ shkxpzData.remark || '--' }}</el-descriptions-item>
        <el-descriptions-item label="收款金额" v-if="fieldShowFunc('kc_amount_collected')">{{ shkxpzData.amount_collected?shkxpzData.amount_collected+'元':'--' }}</el-descriptions-item>
        <el-descriptions-item label="收款凭证" v-if="fieldShowFunc('kc_voucher_file')">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name" v-for="(item, index) in shkxpzData.payment_voucher" :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <el-form :model="kcfdkqrRuleForm" :rules="kcfdkqrRules" ref="kcfdkqrRuleForm" label-position="top">
        <el-form-item label="" prop="radio">
          <el-radio-group v-model="kcfdkqrRuleForm.radio">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input :rows="4" class="input-box" v-model="kcfdkqrRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button @click="kcfdkqrCancel('kcfdkqrRuleForm')">关闭</el-button>
      <el-button type="primary" @click="kcfdkqrSubmit('kcfdkqrRuleForm')" :disabled="diaLoading" :loading="diaLoading">确
        定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {

    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    shkxpzData: {
      required: false,
    },
    fieldList:{
      required: false,
    }
  },
  data() {
    return {
      kcfdkqrVisible: false,
      kcfdkqrRuleForm: {
        remark: "",
        radio: 1
      },
      kcfdkqrRules: {
        // account_manager_id: [
        //   { required: true, message: "请选择客户经理", trigger: "change" },
        // ],
      },
      diaLoading: false,
      receiving_account_name: ''
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.kcfdkqrVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() { },
  methods: {
    // 判断是否显示
    fieldShowFunc(field) {
      let fieldList = this.fieldList;
      return fieldList[field] == undefined ? true : fieldList[field];
    },
    // 勘场费打款确认
    kcfdkqrCancel(formName) {
      this.kcfdkqrRuleForm = {
        remark: "",
        radio: 1
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        // this.kcfdkqrVisible = false;
        this.$emit("onClose", true);
      });
    },
    kcfdkqrSubmit(formName) {
      let kcfdkqrRuleForm = this.kcfdkqrRuleForm;
      console.log(kcfdkqrRuleForm, "勘场费打款确认");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          if (kcfdkqrRuleForm.radio == 2) {
            projectApi
              .financialRejection({
                project_id: this.project_id,
                remark: kcfdkqrRuleForm.remark,
              })
              .then((res) => {
                this.diaLoading = false;
                console.log(res, "财务驳回");
                if (res.code == 200) {
                  this.$emit("onSuccess", true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          projectApi
            .confirmSurveySiteExpenses({
              project_id: this.project_id,
              remark: kcfdkqrRuleForm.remark,
            })
            .then((res) => {
              this.diaLoading = false;
              console.log(res, "勘场费打款确认");
              if (res.code == 200) {
                // this.getProjectDetails();
                // this.kcfdkqrCancel("kcfdkqrRuleForm");
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>